var Windows = function(x, y, w, h)
{
	this.go = new GameObject(x, y, w, h);
	
	this.img = new Array();	
	
	this.img[0] = new Image();
	this.img[0].src = "Images/Janela.png";
	
	this.img[1] = new Image();
	this.img[1].src = "Images/Janela1.png";
	
	this.img[2] = new Image();
	this.img[2].src = "Images/Janela2.png";
	
	this.img[3] = new Image();
	this.img[3].src = "Images/Janela3.png";
	
	this.img[4] = new Image();
	this.img[4].src = "Images/Janela4.png";
	
	this.num = new Array;
	this.num[0] = 0;
	this.num[1] = 0;
	this.num[2] = 0;
	this.num[3] = 0;
	this.num[4] = 0;
	this.num[5] = 0;
	
	this.go.x = new Array();
	this.go.x[0] = 190;
	this.go.x[1] = 310;
	this.go.x[2] = 430;
	this.go.x[3] = 550;
	this.go.x[4] = 190;
	this.go.x[5] = 550;
	
	this.go.y = new Array();
	this.go.y[0] = 180;
	this.go.y[1] = 180;
	this.go.y[2] = 180;
	this.go.y[3] = 180;
	this.go.y[4] = 300;
	this.go.y[5] = 300;
	
	this.collision = true;
	
	this.crack = new Audio("Audios/Janela.mp3");

	this.update = function()
	{
		this._Collision_Player();
		
		if(background.count <= 0)
		{
			background.count = 0;
			sceneManager.GameOver();
		}
		
		if(this.num[0] >= 4 &&
		   this.num[1] >= 4 &&
		   this.num[2] >= 4 &&
		   this.num[3] >= 4 &&
		   this.num[4] >= 4 &&
		   this.num[5] >= 4 &&
		   background.count <= 30)
		{
			sceneManager.GameOver();
		}
		
		if(this.num[0] >= 4 &&
		   this.num[1] >= 4 &&
		   this.num[2] >= 4 &&
		   this.num[3] >= 4 &&
		   this.num[4] >= 4 &&
		   this.num[5] >= 4 &&
		   background.count > 30)
		{
			sceneManager.Congratulation();
		}
	}
	
	this.draw = function()
	{
		for(var i = 0; i < 6; i++)
			graphics.DrawImage(this.img[this.num[i]], this.go.x[i], this.go.y[i]);
	}
	
	this._Collision_Player = function()
	{
		if(this.go.x[0] + this.go.w > player.go.x               &&
		   this.go.x[0]                < player.go.x + player.go.w &&
		   this.go.y[0] + this.go.h > player.go.y               &&
		   this.go.y[0]                < player.go.y + player.go.h &&
		   player.Space && this.collision)
		{
			if(sceneManager.audio)
			{
				this.crack.play();
			}
		
			this.num[0] += 1;
			sleep.wait(30);
			this.collision = false;
			
			if(this.num[0] >= 4)
			{
				this.num[0] = 4;
			}
		}
		
		if(this.go.x[1] + this.go.w > player.go.x               &&
		   this.go.x[1]                < player.go.x + player.go.w &&
		   this.go.y[1] + this.go.h > player.go.y               &&
		   this.go.y[1]                < player.go.y + player.go.h &&
		   player.Space && this.collision)
		{
			if(sceneManager.audio)
			{
				this.crack.play();
			}
			
			this.num[1] += 1;
			sleep.wait(30);
			this.collision = false;
			
			if(this.num[1] >= 4)
			{
				this.num[1] = 4;
			}
		}
		
		if(this.go.x[2] + this.go.w > player.go.x               &&
		   this.go.x[2]                < player.go.x + player.go.w &&
		   this.go.y[2] + this.go.h > player.go.y               &&
		   this.go.y[2]                < player.go.y + player.go.h &&
		   player.Space && this.collision)
		{
			if(sceneManager.audio)
			{
				this.crack.play();
			}
			
			this.num[2] += 1;
			sleep.wait(30);
			this.collision = false;
			
			if(this.num[2] >= 4)
			{
				this.num[2] = 4;
			}
		}
		
		if(this.go.x[3] + this.go.w > player.go.x               &&
		   this.go.x[3]                < player.go.x + player.go.w &&
		   this.go.y[3] + this.go.h > player.go.y               &&
		   this.go.y[3]                < player.go.y + player.go.h &&
		   player.Space && this.collision)
		{
			if(sceneManager.audio)
			{
				this.crack.play();
			}
			
			this.num[3] += 1;
			sleep.wait(30);
			this.collision = false;
			
			if(this.num[3] >= 4)
			{
				this.num[3] = 4;
			}
		}
		
		if(this.go.x[4] + this.go.w > player.go.x               &&
		   this.go.x[4]                < player.go.x + player.go.w &&
		   this.go.y[4] + this.go.h > player.go.y               &&
		   this.go.y[4]                < player.go.y + player.go.h &&
		   player.Space && this.collision)
		{
			if(sceneManager.audio)
			{
				this.crack.play();
			}
			
			this.num[4] += 1;
			sleep.wait(30);
			this.collision = false;
			
			if(this.num[4] >= 4)
			{
				this.num[4] = 4;
			}
		}
		
		if(this.go.x[5] + this.go.w > player.go.x               &&
		   this.go.x[5]                < player.go.x + player.go.w &&
		   this.go.y[5] + this.go.h > player.go.y               &&
		   this.go.y[5]                < player.go.y + player.go.h &&
		   player.Space && this.collision)
		{
			if(sceneManager.audio)
			{
				this.crack.play();
			}
			
			this.num[5] += 1;
			sleep.wait(30);
			this.collision = false;
			
			if(this.num[5] >= 4)
			{
				this.num[5] = 4;
			}
		}
	}
}

var windows = new Windows(500, 300, 66, 100);